

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import org.json.JSONArray;
import org.json.JSONObject;

import com.google.gson.Gson;

import droid.net.playcabbage.asynctask.MyAsyncTask;
import droid.net.playcabbage.bean.CheckinBeanReal;




import android.os.Bundle;
import android.os.StrictMode;
import android.app.Fragment;
import android.app.ListActivity;
import android.util.Log;
import android.view.Window;
import android.widget.ArrayAdapter;

public class NewList extends ListActivity {

	static ArrayList<String> checkinList = new ArrayList<String>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
				
		MyAsyncTask mat = new MyAsyncTask(this);
		mat.execute("http://playcabbage.net/rest/checkins/getjson");
		
		ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.activity_list_item, android.R.id.text1,checkinList);
		this.setListAdapter(aa);

	}
	
	public void buildList(String s) {
		try {
			JSONArray jsonArray = new JSONArray(s);
			Log.i(NewList.class.getName(),
					"Number of entries " + jsonArray.length());
			for (int i = 0; i < jsonArray.length(); i++) {
				JSONObject jsonObject = jsonArray.getJSONObject(i);
				String json = jsonObject.toString();
				Gson gson = new Gson();
				CheckinBeanReal bean = gson.fromJson(json,CheckinBeanReal.class);
			checkinList.add(bean.getName() + " " + bean.getUrlstring() + " " + bean.getCheckinDate() + " " + bean.getCheckinTime());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}
